package com.twotwoshop.service.user.controller;

import com.twotwoshop.domin.common.enums.AppHttpCodeEnum;
import com.twotwoshop.domin.user.dtos.LoginDto;
import com.twotwoshop.domin.user.pojos.ApUser;
import com.twotwoshop.fegin.api.goods.IGoodsClient;
import com.twotwoshop.service.user.service.IUserService;
import com.twotwoshop.domin.common.dtos.ResponseResult;
import com.twotwoshop.util.AliOssUtil;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.UUID;


@RestController
@RequestMapping("/user")//
@Slf4j
@RequiredArgsConstructor
public class UserLoginController {


    private final IUserService userService;


    /**
     * 发送手机验证码
     */
    @PostMapping("/code")
    public ResponseResult sendCode(@RequestBody LoginDto loginDto) {

        log.info("发送短信验证码...");

        return userService.sendCode(loginDto);
    }


    /**
     * app端用户登录
     * @param dto
     * @return
     */
    @PostMapping("/login")
    public ResponseResult login(@RequestBody LoginDto dto) {

        log.info("user login......");

        return userService.login(dto);
    }

    /**
     * app端用户登出
     * @return
     */
    @PostMapping("/logout")
    public ResponseResult loginOut(@RequestHeader(value = "Authorization", required = true) String token) {

        log.info("user login......");

        return userService.loginOut(token);
    }



    /**
     * 获取用户信息
     * @return
     */
    @GetMapping("/info")
    public ResponseResult getUserInfo() {

        log.info("user info......");

        return userService.getuserInfo();

    }


    /**
     * 根据用户id获取自己信息
     * @return
     */
    @GetMapping("/info/{id}")  // 修改为正确的用户服务API路径
    ResponseResult getUserInfoById(@PathVariable("id") Long id){

        log.info("user info......");

        return userService.getUserInfoById(id);

    }


    /**
     * 更改用户信息
     * @return
     */
    @PostMapping("/update")
    public ResponseResult updateUserInfo(@RequestBody ApUser apUser) {

        log.info("user update......");

        return userService.updateUserInfo(apUser);

    }


    /**
     * 根据用户id获取卖家信息
     * @return
     */
    @GetMapping("/seller/{userId}")  // 修改为正确的用户服务API路径
    ResponseResult getsellerInfoById(@PathVariable("userId") Long id){

        log.info("seller id......");

        return userService.getsellerInfoById(id);

    }





}